<template>
  <div>
    <div class="xloop-main">
      <div class="title-img"><img src="https://img.wifenxiao.com/h5-wfx/images/freeQueuing/freeTitle.png"></div>
      <div class="rewards-list">
        <div v-for="item in free_lst" :key="item.number" class="show_main">
          <div class="message">
            <img class="goods-img" :src="item.item_info[0].is_compress === 1 ? item.item_info[0].image + '180x180':item.item_info[0].image" alt="">
            <div class="user-info">
              <img class="head_img" :src="item.head_img">
              <div class="nickname">{{ item.nick_name}}</div>
            </div>
          </div>
          <div class="number">{{ item.number }}号</div>
        </div>
        <div v-if="free_lst.length < 4" class="show_main">
          <div class="message">
            <img class="goods-img" src="https://img.wifenxiao.com/h5-wfx/images/freeQueuing/noData.png" alt="">
          </div>
          <div class="number">火热进行中</div>
        </div>
        
      </div>

      <div class="my_rewards" :class="rewards.is_my_doing ? 'two-column': ''">
        <div class="rewards" v-if="rewards.doing_number > 0">
          <div class="rewards-title">免单中</div>
          <div class="rewards-money"><span class="money-num">{{ rewards.doing_number }}</span></div>
        </div>
        <div class="rewards" v-if="rewards.is_my_doing">
          <div class="rewards-title">待返金额</div>
          <div class="rewards-money"><span class="money-num" v-html="scaleGoodsPriceFn(rewards.return_money)"></span></div>
        </div>
        <div class="rewards">
          <div class="rewards-title">参与单数</div>
          <div class="rewards-money">{{ rewards.queue_number }}</div>
        </div>
        <div class="rewards">
          <div class="rewards-title">已返金额</div>
          <div class="rewards-money"><span class="money-num" v-html="scaleGoodsPriceFn(rewards.issued_money)"></span></div>
        </div>
      </div>
    </div>
    <div class="whole-xloop">
      <div class="my_promotion">
        <div class="title">我的奖励</div>
      </div>
      <div class="activity-list">
        <van-list
          v-model="loading"
          :finished="finished"
          :error.sync="error"
          error-text="请求失败，点击重新加载"
          finished-text=""
          @load="onLoad"
        >
          <div class="list" v-for="item in list" :key="item.id">
            <div class="free-num" :class="item.status == 2 ? 'already-status':item.status == 0 ? 'wait-status': ''">{{item.number}}号</div>
            <div class="buyer buy-order">
              <div class="status" :class="item.status == 2 ? 'already-status':item.status == 0 ? 'wait-status': ''">{{ item.status_name }}</div>
              <div class="order-no">订单编号：{{ item.order_no }}</div>
              <div>下单时间：{{ item.add_order_time }}</div>
              <div class="order-detail-buy" v-for="goods in item.item_info" :key="goods.item_id">
                <div class="order-img" @click="jumpName('item-detail', {detailId: goods.item_id})">
                  <img :src="goods.is_compress === 1 ? goods.image + '180x180':goods.image" alt="">
                </div>
                <div class="order-title order-show">
                  <div class="min-title">{{ goods.item_title }}</div>
                  <div class="sub-title">{{ goods.sku_name }}</div>
                </div>
                <div class="order-show" style="text-align: right;">
                  <div>x{{ goods.num }}</div>
                  <div><span class="money-num" v-html="scaleGoodsPriceFn(goods.payment)"></span></div>
                </div>
              </div>
            </div>
            <div class="order-get">
              <div class="order" v-if="item.return_point > 0">
                <div class="order-title">赠送积分</div>
                <div class="order-num">{{item.return_point}}</div>
              </div>
              <div class="order">
                <div class="order-title">返还金额</div>
                <div class="order-num"><span class="money-num" v-html="scaleGoodsPriceFn(item.return_money)"></span></div>
              </div>
            </div>
            <div class="check-btn" v-if="info.is_first_order === '0'" @click="jumpGoods(item)">再来一单</div>
          </div>
        </van-list>
      
      </div>

    </div>
  </div>
</template>
<script>
import { scaleGoodsPrice } from '@/utils/index.js'
import Search from '@/components/Search/index'
import { freeOrderRewardDetail } from '@/api/user/freeQueuing/freeQueuing.js'

export default {
  components: {
    Search
  },
  data() {
    return {
      searchInfo: {
        placeholder: '请输入活动名称搜索'
      },
      rewards: {
        doing_number: 0,
        is_my_doing: 0,
        // return_money: 0,
        queue_number: 0,
        issued_money: 0
      },
      info: {
        id: '',
        is_first_order: ''
      },
      list: [],
      p: 1,
      loading: false,
      error: false,
      finished: false,
      free_lst: []
    }
  },
  mounted() {
    // 小程序触底加载更多
    window.addEventListener('reachbottom', () => {
      this.onLoad()
    })
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      freeOrderRewardDetail({ p: this.p, activity_id: this.$route.query.id }).then(res => {
        this.finished = false
        this.loading = false
        if (res.status == 1) {
          if (res.data && res.data.list.length > 0) {
            if (this.p == 1) {
              this.rewards = res.data.info
              this.info = res.data.activity_info
              this.list = res.data.list
              this.free_lst = res.data.free_lst
            } else {
              this.list.push(...res.data.list)
            }
            this.p++
          } else {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 加载更多
    onLoad() {
      // this.finished = false
      this.init()
    },
    jumpGoods(data) {
      console.log('data', data)
      if(data.item_info.length > 1) {
        this.jumpName('item-list', { link: 3, activity_id: this.info.id })
      } else {
        this.jumpName('item-detail', { detailId: data.item_info[0].item_id })
      }
    },
    jumpName(name, data) {
      this.$JumpName(this, name, data)
    },
    scaleGoodsPriceFn(price) {
      return scaleGoodsPrice(price)
    },
    // 点击搜索
    searchFn(keyword) {
      this.p = 1
      this.title = keyword
      this.finished = false
      this.list = []
      // this.init()
    }
  }
}
</script>
<style lang="scss">
  .rewards-money{
    .money-num {
      .price-scale {
        font-size: 24px;
        color: #fff;
        font-weight: 700;
        .num-font{
          font-size: 40px;
          color: #fff;
          font-weight: 700;
        }
      }
    }
  }
  .order-num {
    .money-num {
      .price-scale {
        font-size: 24px;
        color:#FD4149;
        font-weight: 700;
        .num-font{
          font-size: 40px;
          color: #FD4149;
          font-weight: 700;
        }
      }
    }
  }
  .xloop-main {
    background: url("https://img.wifenxiao.com/h5-wfx/images/freeQueuing/freeBg.png") top left no-repeat;
    background-size: 100% auto;
    padding: 16px 16px 0 16px;
    .title-img {
      margin: 48px auto 24px;
      width: 462px;
      img {
        width: 100%;
      }
    }
    .rewards-list {
      background: linear-gradient(180deg, #FEF6DF 0%, #FEFDF9 100%);
      // height: 244px;
      border-radius: 12px;
      margin-bottom: 24px;
      padding: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      .show_main {
        width: 156px;
        margin-left: 16px;
        &:first-child {
          margin-left: 0;
        }
        .message {
          border-radius: 8px;
          width: 156px;
          height: 156px;
          position: relative;
          overflow: hidden;
          .goods-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          .user-info {
            background: url("https://img.wifenxiao.com/h5-wfx/images/freeQueuing/userBg.png") top left no-repeat;
            background-size: 100% 100%;
            // @include lineClamp(24px,24,1);
            // height: 60px;
            display: flex;
            padding: 28px 8px 8px 8px;
            align-items: end;
            position: absolute;
            left: 0;
            width: 100%;
            bottom: 0;
            
            .head_img {
              width: 24px;
              height: 24px;
              border-radius: 50%;
              margin-right: 8px;
            }
            .nickname {
              color: #fff;
              font-size: 20px;
              overflow: hidden; 
              text-overflow:ellipsis;
              white-space: nowrap;
            }
          }
        }
        .number {
          margin-top: 12px;
          font-size: 24px;
          text-align: center;
        }
      }
    }
    .my_rewards {
      padding: 32px 0;
      background: linear-gradient(180deg, #FE754F 0%, #FD4149 100%);
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      text-align: center;
      position: relative;
      // min-height: 184px;
      font-size: 24px;
      &.two-column {
        flex-wrap: wrap;
        .rewards {
          width: 50%;
          &:nth-child(3),&:nth-child(4) {
            margin-top: 32px
          }
        }
      }
      .rewards {
        color: #fff;
        // margin: 16px 0;
        .rewards-title {
          margin-bottom: 14px;
        }
        .rewards-money {
          color: #fff;
          font-size: 40px;
          font-weight: 700;
        }
      }
    }
  }
  .whole-xloop {
    padding: 12px 16px 16px 16px;
    .my_promotion {
      // margin: 24px 0;
      .promotion {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 16px;
        .sub_title {
          font-size: 24px;
          img {
            width: 24px;
            height: 24px;
            position: relative;
            top: 2px;
            margin-left: 8px;
          }
        }
      }
    }
    .activity-list {
      .list {
        border-radius: 12px;
        background: #fff;
        padding: 24px;
        position: relative;
        margin-bottom: 16px;
        .free-num {
          background: linear-gradient(0deg, #FD4149, #FD4149),linear-gradient(180deg, #FE754F 0%, #FD4149 103.23%);
          border-bottom-left-radius: 12px;
          border-top-right-radius: 12px;
          font-size: 24px;
          padding: 12px;
          color: #fff;
          position: absolute;
          right: 0;
          top: 0;
          &.already-status {
            background: #67C23A;
          }
          &.wait-status {
            background: #E6A23C;
          }
        }
        .order-get {
          display: flex;
          justify-content: space-around;
          align-items: center;
          padding: 24px 0;
          // border-bottom: 2px solid #F2F3F5;
          .order {
            text-align: center;
            .order-title {
              font-size: 24px;
              color: #999;
              margin-bottom: 16px;
            }
            .order-num {
              color: #FD4149;
              font-size: 40px;
              font-weight: 700;
            }
          }
        }
        .check-btn {
          text-align: center;
          font-size: 32px;
          padding: 16px 0;
          border: 1px solid #FD4149;
          border-radius: 8px;
          background: #FD4149;
          color: #fff;
            
        }
      }
    }
    .title {
      color: #333;
      font-size: 28px;
      font-weight: 500;
      padding: 16px 0;
      margin-left: 8px;
      line-height: 140%;
      &.list-title {
        width: 80%;
        padding: 0;
        margin-left: 0px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;

      }
    }
  }
  .data-btn {
    display: flex;
    align-items: center;
    justify-content:space-around;
    margin: 0 40px;
    .check-superior {
      border-radius: 200px;
      border: 2px solid #FD4149;
      color: #FD4149;
      font-size: 28px;
      width: 290px;
      height: 72px;
      line-height: 72px;
      text-align: center;
    }
    .go-shopping {
      border-radius: 200px;
      background: linear-gradient(90deg, #FE754F -0.78%, #FD4149 99.06%), linear-gradient(92deg, #00ADBD 1.71%, #04C1AB 98.29%);
      color: #fff;
      font-size: 28px;
      width: 290px;
      height: 72px;
      line-height: 72px;
      text-align: center;
    }
  }
  .no-data {
    padding: 72px 0!important;
  }

  .buyer {
    padding-bottom: 24px;
    border-bottom: 1px solid #F2F3F5;
    &.buy-order {
      padding-bottom: 24px;
      position: relative;
      font-size: 28px;
      line-height: 140%;
      .order-no {
        margin-bottom: 8px;
      }
      .status {
        position: absolute;
        top: 44px;
        right: -20px;
        color: #FD4149;
        width: 30%;
        text-align: right;
        &.already-status {
          color: #67C23A;
        }
        &.wait-status {
          color: #E6A23C;
        }
      }
      .order-detail-buy {
        margin-top: 24px;
        align-items: self-start;
        display: flex;
        .order-img {
          img {
            width: 128px;
            height: 128px;
            border-radius: 8px;
            object-fit: cover;
          }
        }
        .order-show {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          // margin-bottom: 10px;
          height: 128px;
        }
        .order-title {
          margin-left: 16px;
          margin-right: 32px;
          flex: 1;
          .min-title {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
          }
          .sub-title {
            color: #999;
            margin-top: 8px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
          }
        }
      }
    }
  }

</style>